"""
    页面对象编写技巧
        类名：使用大驼峰将模块名称抄进来，有下划线去掉下划线
        方法：根据业务需求每个操作步骤单独封装一个方法
            方法名 page_XXX
"""
from time import sleep

from selenium import webdriver


class PageLogin:
    def __init__(self):
        # 获取浏览器对象
        self.driver = webdriver.Chrome()
        # 最大化浏览器
        self.driver.maximize_window()
        # 隐式等待
        self.driver.implicitly_wait(30)
        # 打开url
        self.driver.get("https://demo.ruoyi.vip/login")

    # 点击登录 连接
    def page_click_login_link(self):
        # self.driver.find_element_by_partial_link_text("登录").click()
        pass

    # 输入用户名
    def page_input_username(self, username_val):
        username = self.driver.find_element_by_css_selector('[name="username"]')
        username.clear()
        username.send_keys(username_val)

    # 输入密码
    def page_input_pwd(self, pwd_val):
        pwd = self.driver.find_element_by_css_selector('[name="password"]')
        pwd.clear()
        pwd.send_keys(pwd_val)

    # 输入验证码
    def page_input_verify_code(self, code_val):
        code = self.driver.find_element_by_css_selector('[name="validateCode"]')
        code.clear()
        code.send_keys(code_val)

    # 点击登录按钮
    def click_login_btn(self):
        self.driver.find_element_by_id('btnSubmit').click()

    # 获取异常提示信息
    def page_get_text(self):
        sleep(0.5)
        return self.driver.find_element_by_css_selector('.layui-layer-content').text

    # 点击提示框确定按钮
    def page_click_err_btn_ok(self):
        pass

    # 组装登录业务方法 给业务层
    def page_login(self, username, pwd, code):
        self.page_click_login_link()
        self.page_input_username(username)
        self.page_input_pwd(pwd)
        self.page_input_verify_code(code)
        self.click_login_btn()
